<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"

      xmlns:f="http://java.sun.com/jsf/core">
    <ui:composition template="layout.xhtml">
        <ui:define name="body">
            <h:form id="cepForm" enctype="multipart/form-data">
                <h1 class="title">Escrituras de Testamento</h1>
                <p:growl id="messages" showDetail="true" autoUpdate="true" /> 
                <div class="row">
                    <div class="twelve columns"> 
                        <fieldset>
                            <legend> <h4 style="margin:0 0 10px 0">Cadastro</h4></legend>
                            <p:panel id="charterPanel" style="background: none; border: none;" 
                                     styleClass="container_24 clearfix ">
                                
                                <p:outputLabel value="Número: " styleClass="grid_3"/>
                                <p:inputText styleClass="grid_8" value="#{managerSearchRcto.charterEdit.esc}"/>

                                <div class="clear"/>
                                
                                <p:outputLabel value="Tipo Ato: " styleClass="grid_3"/>
                                <p:autoComplete styleClass="grid_8" style="width: 28.44%"
                                                dropdown="true" converter="actcepconverter"   
                                                var="actCepValue" itemLabel="#{actCepValue.description}" 
                                                scrollHeight="200" forceSelection="true"
                                                itemValue="#{actCepValue}" value="#{managerSearchRcto.charterEdit.actCep}"
                                                completeMethod="#{managerActCep.autocomplete}" />  


                                <p:outputLabel value="Data Ato: " styleClass="grid_5"/>
                                <p:calendar showOn="button" styleClass="grid_8" style="width:32.44%"
                                            value="#{managerSearchRcto.charterEdit.dateTest}"/>

                                <div class="clear"/>

                                <p:outputLabel value="Livro: " styleClass="grid_3" />
                                <p:inputMask mask="?999999999"  placeHolder=""  styleClass="grid_8" value="#{managerSearchRcto.charterEdit.book}"/>

                                <p:outputLabel value="Livro Compl.: " styleClass="grid_4"/>
                                <p:inputText styleClass="grid_8" value="#{managerSearchRcto.charterEdit.bookComp}"/> 

                                <div class="clear"/>

                                <p:outputLabel value="Folha: " styleClass="grid_3" />
                                <p:inputMask mask="?999999999"  placeHolder=""  styleClass="grid_8" value="#{managerSearchRcto.charterEdit.leaf}"/> 

                                <p:outputLabel value="Folha Compl.: " styleClass="grid_4"/>
                                <p:inputText styleClass="grid_8" value="#{managerSearchRcto.charterEdit.leafComp}"/> 


                                <div class="clear"/>
                                <p:outputLabel value="Objeto: " styleClass="grid_3"/>
                                <p:inputTextarea cols="100" rows="4" 
                                                 styleClass="grid_20" value="#{managerSearchRcto.charterEdit.obs}"/> 


                                <fieldset>
                                    <legend> <h4 style="font-size: 10px;margin:0 0 10px 0">Revogação</h4></legend>
                                    <div class="clear"/>

                                    <p:outputLabel value="Data do Ato Revogado: " styleClass="grid_3"/>
                                    <p:calendar showOn="button" styleClass="grid_8" style="width:32.44%"
                                                value="#{managerSearchRcto.charterEdit.revocationDateTest}"/>

                                    <div class="clear"/>

                                    <p:outputLabel value="Livro: " styleClass="grid_3" />
                                    <p:inputMask mask="?999999999"  placeHolder=""  styleClass="grid_8" value="#{managerSearchRcto.charterEdit.revocationBook}"/>

                                    <p:outputLabel value="Livro Compl.: " styleClass="grid_4"/>
                                    <p:inputText styleClass="grid_8" value="#{managerSearchRcto.charterEdit.revocationBookComp}"/> 

                                    <div class="clear"/>

                                    <p:outputLabel value="Folha: " styleClass="grid_3" />
                                    <p:inputMask mask="?999999999"  placeHolder=""  styleClass="grid_8" value="#{managerSearchRcto.charterEdit.revocationLeaf}"/> 

                                    <p:outputLabel value="Folha Compl.: " styleClass="grid_4"/>
                                    <p:inputText styleClass="grid_8" value="#{managerSearchRcto.charterEdit.revocationLeafComp}"/> 

                                    <div class="clear"/>

                                    <p:outputLabel value="Cidade: " styleClass="grid_3"/>
                                    <p:autoComplete styleClass="grid_8" style="width: 28.44%" dropdown="true" converter="cityconverter"   
                                                    var="cityValue" itemLabel="#{cityValue.name}" value="#{managerSearchRcto.charterEdit.revocationCity}"
                                                    itemValue="#{cityValue}" scrollHeight="200"
                                                    completeMethod="#{managerActCep.autocompleteCity}" /> 
                                    <p:outputLabel value="Estado: " styleClass="grid_5"/>
                                     <p:autoComplete styleClass="grid_8" style="width: 28.44%" dropdown="true" converter="countryconverter"   
                                                    var="countryValue" itemLabel="#{countryValue.name}"  value="#{managerSearchRcto.charterEdit.revocationUF}"
                                                    itemValue="#{countryValue}" scrollHeight="200" forceSelection="true"
                                                    completeMethod="#{managerCountry.countrys}" />
                                    <div class="clear"/>
                                    <p:outputLabel value="Cartório " styleClass="grid_3"/>
                                    <p:inputText  styleClass="grid_20" value="#{managerSearchRcto.charterEdit.revocationNottaryOffice}" />
                                </fieldset>


                            </p:panel>

                        </fieldset>
                        <fieldset>
                            <legend> <h4 style="margin:0 0 10px 0">TESTADOR</h4></legend>

                            <p:panel id="partsPanel" style="background: none; border: none;" styleClass="container_24 clearfix ">

                                <p:outputLabel id="typeDocumentLabel" 
                                               value="CPF: " 
                                               styleClass="grid_3"/>

                                <p:inputMask id="typeDocumentInput" 
                                             value="#{managerSearchRcto.peopleEdit.cpf}"
                                             mask="999.999.999-99"
                                             styleClass="grid_8"  > 
                                    <p:ajax event="blur" update=":cepForm:partsPanel" 
                                            onstart="bui.show()" oncomplete="bui.hide()"
                                            listener="#{managerSearchRcto.ajaxVerifyPeopleExistEdit()}" />
                                </p:inputMask>

                                <p:blockUI block=":cepForm:partsPanel" widgetVar="bui" > 
                                    <p:graphicImage value="media/css/images/ajax-loader.gif"/>
                                </p:blockUI> 

                                <div class="clear"/>

                                <p:outputLabel value="Nome:" styleClass="grid_3" />
                                <p:inputText styleClass="grid_20" 
                                             value="#{managerSearchRcto.peopleEdit.name}"/> 

                                <div class="clear"/>

                                <p:outputLabel value="RG: "  styleClass="grid_3"/>
                                <p:inputText styleClass="grid_8" value="#{managerSearchRcto.peopleEdit.rg}"/> 

                                <p:outputLabel value="Orgão emissor: "  styleClass="grid_4"/>
                                <p:inputText styleClass="grid_8" value="#{managerSearchRcto.peopleEdit.organ}"/> 

                                <div class="clear"/>

                                <p:outputLabel value="Data nasc: "  styleClass="grid_3"/>
                                <p:calendar showOn="button" styleClass="grid_8" style="width:32.44%" 
                                            value="#{managerSearchRcto.peopleEdit.nasc}"/> 

                                <div class="clear"/>
                                <p:outputLabel value="Pai:" styleClass="grid_3" />
                                <p:inputText styleClass="grid_20" 
                                             value="#{managerSearchRcto.peopleEdit.father}"/> 

                                <div class="clear"/>
                                <p:outputLabel value="Mãe:" styleClass="grid_3" />
                                <p:inputText styleClass="grid_20" 
                                             value="#{managerSearchRcto.peopleEdit.mother}"/> 


                            </p:panel>
                        </fieldset>
                        <fieldset>
                            <legend> <h4 style="margin:0 0 10px 0">Selos</h4></legend>

                            <p:panel id="stampPanel" 
                                     style="background: none; border: none;" styleClass="container_24 clearfix ">

                                <p:outputLabel value="Série: "   styleClass="grid_3"/>
                                <p:inputText  styleClass="grid_8" value="#{managerSearchRcto.stampEdit.serie}"/> 

                                <p:outputLabel value="Número: "  styleClass="grid_4"/>
                                <p:inputText  styleClass="grid_8" value="#{managerSearchRcto.stampEdit.number}"/> 

                                <p:outputLabel value="Tipo Selo: "  styleClass="grid_3" />
                                <p:autoComplete styleClass="grid_8" style="width: 28.44%" dropdown="true"
                                                converter="typestampconverter"   
                                                value="#{managerRcto.typeStampObj}"
                                                var="typeStampValue" itemLabel="#{typeStampValue.name}" 
                                                itemValue="#{typeStampValue}"
                                                completeMethod="#{managerTypeStamp.autoComplete}" >

                                    <p:column style="width:20%;text-align:center;background-color: \##{typeStampValue.color};">  
                                    </p:column>  

                                    <p:column style="width:80%">  
                                        #{typeStampValue.name} 
                                    </p:column>
                                </p:autoComplete>

                                <div class="clear"/>

                                <div class="buttonAction">
                                    <p:commandButton value="Adicionar" actionListener="#{managerSearchRcto.addStampsEdit()}"
                                                     icon="ui-icon-plus" 
                                                     process="@this, :cepForm:stampPanel, 
                                                     :cepForm:dataTableStamps"
                                                     update=":cepForm:stampPanel, 
                                                     :cepForm:dataTableStamps" styleClass="ui-priority-primary" />
                                    <p:commandButton value="Limpar"  icon="ui-icon-trash" />
                                </div>

                                <p:dataTable id="dataTableStamps"
                                             value="#{managerSearchRcto.charterEdit.stamp}"
                                             var="stampTable"
                                             emptyMessage="Nenhum registro encontrado" >
                                    <f:facet name="header">
                                        Selos
                                    </f:facet>
                                    <p:column headerText="Série">
                                        #{stampTable.serie}
                                    </p:column>
                                    <p:column headerText="Número">
                                        #{stampTable.number}
                                    </p:column>
                                    <p:column headerText="Tipo">
                                        #{stampTable.typeStamp.name}
                                    </p:column>

                                </p:dataTable>
                            </p:panel>
                        </fieldset>
                        <br/>

                        <fieldset>
                            <legend> <h4 style="margin:0 0 10px 0">Anexos</h4></legend>


                            <p:fileUpload 
                                mode="advanced"  
                                label="Anexar"
                                fileUploadListener="#{managerSearchRcto.handle}"
                                multiple="true" 
                                auto="true"
                                invalidFileMessage="Tipo de arquivo não suportado."
                                invalidSizeMessage="Tamanho do arquivo não é suportado"
                                uploadLabel="Enviar"
                                cancelLabel="Cancelar"
                                allowTypes="/(\.|\/)(gif|tif|tiff|jpe?g|png|pdf)$/"/> 
                            
                            
                            <p:panel id="annexPanel" 
                                     style="background: none; border: none;" styleClass="container_24 clearfix ">

                                <ui:repeat  value="#{managerSearchRcto.charterEdit.annex}" var="a">
                                    <h:outputLink  
                                        value="#{a.type ne 'application/pdf' ? 'viewImage':'show'}" title="#{a.description}"  target="_blank" >

                                        <div style="text-align: center; width: 20%;" class="grid_4">

                                            <p:graphicImage styleClass="image grid_3" rendered="#{a.type ne 'application/pdf'}"
                                                            style="margin-left:1%; width: 100px;"
                                                            url="show/?annex=#{a.id}" />

                                            <p:outputLabel  value="#{a.description.length() ge 10 ? a.description.substring(0, 10).concat('...') : 
                                                                     a.description.replace('.png','').replace(' ','_')}" 
                                                            style="margin-left:1%; width: 100px;" rendered="#{a.type ne 'application/pdf'}"/>

                                            <p:graphicImage styleClass="image grid_3" rendered="#{a.type eq 'application/pdf'}"
                                                            style="margin-left:1%; width: 100px;" 
                                                            url="assets/images/pdf.jpeg" />


                                            <p:outputLabel  value="#{a.description.length() ge 10 ? a.description.substring(0, 10).concat('...') : 
                                                                     a.description.replace('.pdf','').replace(' ','_')}" 
                                                            style="margin-left:1%; width: 100px;" rendered="#{a.type eq 'application/pdf'}"/>
                                        </div>
                                        <f:param name="annex" value="#{a.id}"/>
                                    </h:outputLink>
                                </ui:repeat>
                            </p:panel>
                        </fieldset>    


                        <div class="buttonAction">
                            <p:commandButton value="Atualizar" icon="ui-icon-disk"
                                             process="@form" update="@form"
                                             actionListener="#{managerSearchRcto.edit()}" styleClass="ui-priority-primary" />
                            <p:commandButton value="Cancelar"  icon="ui-icon-trash" />
                        </div >
                    </div>
                </div>
            </h:form>
        </ui:define>
    </ui:composition>

</html>